package com.origin.app.dialog

import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.origin.app.MyApplication
import com.origin.app.R
import com.origin.app.bean.CompanyBean
import com.origin.app.databinding.DialogBottomCompanyBinding
import com.origin.app.page.company_list.adapter.CompanyAdapter
import com.origin.uilibrary.SelectorFactory

class CompanyListDialog(var list: MutableList<CompanyBean> , var mContext: Context, var action: () -> Unit) : BottomSheetDialogFragment() {

    companion object{
        // 是否多选
        var isMultiple=false
    }



    private val companyAdapter: CompanyAdapter by lazy {
        CompanyAdapter( list,mContext);
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //设置背景透明，才能显示出layout中诸如圆角的布局，否则会有白色底（框）
        setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme);
    }
    lateinit var dialogBottomCompanyBinding: DialogBottomCompanyBinding
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        dialogBottomCompanyBinding = DataBindingUtil.inflate(inflater, R.layout.dialog_bottom_company, container, false)
        dialogBottomCompanyBinding.switchIsMultiple.isChecked=isMultiple;
        dialogBottomCompanyBinding.switchIsMultiple.setOnCheckedChangeListener { compoundButton, b ->

            isMultiple=b;

        }
        dialogBottomCompanyBinding.btnSure.setOnClickListener{
            action.invoke()
            dismiss()
        }
        val r = SelectorFactory.dp2px(MyApplication.getInstance(), 10f)
        dialogBottomCompanyBinding.root.background = SelectorFactory.newShapeSelector()

            .let {
                it.setDefaultBgColor(Color.parseColor("#ffffff"))
            }

            .setCornerRadius(r, r, 0, 0).create()
        dialogBottomCompanyBinding.recyclerView.layoutManager= LinearLayoutManager(mContext)
        dialogBottomCompanyBinding.recyclerView.adapter=companyAdapter
        return dialogBottomCompanyBinding.root
    }
}